import numpy as np

x = np.arange(8)

x = np.append(x, 8)
x = np.append(x, [9, 10])
print(x)

x = np.insert(x, 1, 11) # 下标为1的地方插入11
print(x)

x[3] = 12 # 下标为3的地方的元素的值改为12
print(x)

x = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
x[0, 2] = 4 # (0, 2)的位置的值改为4
print(x, "\n")

x[1:, 1:] = 1 # 切切片把行、列下标 >= 1的地方的值全部改为1
print(x, "\n")

x[1:, 1:] = [11, 22] # 等号两侧的宽度相同
print(x, "\n")

x[1:, 1:] = [[111], [222]] # 等号两侧高度相同
print(x, "\n")

x[1:, 1:] = [[1111, 2222], [3333, 4444]] # 等号两侧形状相同
print(x, "\n")

x = np.array([3 + 4j, 5 - 6j, 7 + 8j])
x.real = 8 # 修改复数的实部全为8
print(x, "\n")

x.real = [8, 9, 10]     # 修改复数的实部[8, 9, 10]
print(x, "\n")

x.imag = 20
print(x, "\n")  # 修改复数的虚部全为20

x.imag = [100, 200, 300] # 修改复数的虚部为100, 200, 300]
print(x, "\n")

x = np.array([8 + 6j, 9 - 6j, 10 + 6j])
x = np.arange(16).reshape(4, 4)
print(x, "\n")
a = np.tril_indices(4) # 生成下三角坐标
print(a, "\n")

# 通过下三角的坐标修改对应元素的值
x[np.tril_indices(4)] = 666
print(x, "\n")

